import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:juming_test/model/home/home_kingkong_model.dart';

class HomeKingkongManagementItem extends StatelessWidget {
  const HomeKingkongManagementItem({
    super.key,
    required this.isActive,
    required this.kingkong,
    required this.isEditing,
    this.onRemove,
    this.onAdd,
  });
  // 是否激活状态
  final bool isActive;
  // 是否在编辑中状态
  final bool isEditing;
  // 金刚位数据
  final HomeKingkongModel kingkong;
  // 事件处理
  // 移除item
  final Function(HomeKingkongModel)? onRemove;
  // 添加item
  final Function(HomeKingkongModel)? onAdd;

  @override
  Widget build(BuildContext context) {
    return Container(
      key: Key(kingkong.id.toString()),
      child: Stack(
        children: [
          Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Image.asset(kingkong.iconPath, width: 40.w, height: 40.w),
                SizedBox(height: 6.w),
                Text(
                  kingkong.title,
                  style: TextStyle(fontSize: 14.sp),
                  textAlign: TextAlign.center,
                ),
              ],
            ),
          ),
          if (isEditing)
            Positioned(
              right: 0,
              top: 0,
              child: GestureDetector(
                onTap:
                    () =>
                        isActive
                            ? onRemove?.call(kingkong)
                            : onAdd?.call(kingkong),
                child: Container(
                  decoration: BoxDecoration(
                    color: isActive ? Colors.grey : Colors.redAccent,
                    shape: BoxShape.circle,
                  ),
                  child: Icon(
                    isActive ? Icons.remove : Icons.add,
                    size: 16,
                    color: Colors.white,
                  ),
                ),
              ),
            ),
        ],
      ),
    );
  }
}
